package cn.sunxyz.behavior.observer;

import java.util.Vector;

/**
 * Created by yangrd on 2017/5/15.
 */
public class ConcreteSubject implements Subject {
    Vector<Observer> vector = new Vector<>();

    @Override
    public void addObserver(Observer observer) {
        vector.add(observer);
    }

    @Override
    public void deleteObserver(Observer observer) {
        vector.remove(observer);
    }

    @Override
    public void notifyObserver() {
        vector.forEach(observer -> observer.update());
    }

    @Override
    public void doSometing() {
        System.out.println("被观察者事件反生");
        this.notifyObserver();
    }
}
